#ifndef __DELAY_H
#define __DELAY_H

#include "stdint.h"

/* ===================== 自定义结构体 ========================== */


/* ====================== 自定义常量 =========================== */

extern volatile uint32_t gMS_TimeCNT;

#define	MS_TIMEBASE()		gMS_TimeCNT++
#define MS_GETTIME(void)	gMS_TimeCNT

#define RUN_BY_LIMIT_BLOCK(ms, BLOCK)           \
{                                               \
    static uint32_t last_exec_ms = 0;           \
    uint32_t cur_ms_tick = MS_GETTIME();   \
    if (cur_ms_tick >= (last_exec_ms + ms))     \
    {                                           \
        BLOCK;                                  \
        last_exec_ms = cur_ms_tick;             \
    }                                           \
}


/* ======================= 对外接口 ============================ */
void delay_us(uint32_t nus);
void delay_ms(uint16_t nms);


#endif /* __DELAY_H */

